#!/bin/bash

echo "开始卸载 HTTP 代理服务器及相关包..."

# 停止并禁用主流 HTTP 代理服务
systemctl stop squid tinyproxy polipo privoxy 2>/dev/null
systemctl disable squid tinyproxy polipo privoxy 2>/dev/null

# 卸载所有主流 HTTP 代理服务器包（兼容 dnf/yum/apt）
if command -v dnf >/dev/null 2>&1; then
    dnf remove -y squid tinyproxy polipo privoxy 2>/dev/null
elif command -v yum >/dev/null 2>&1; then
    yum remove -y squid tinyproxy polipo privoxy 2>/dev/null
elif command -v apt-get >/dev/null 2>&1; then
    apt-get purge -y squid squid3 tinyproxy polipo privoxy 2>/dev/null
fi

# 验证卸载结果
if rpm -qa 2>/dev/null | grep -qE '^(squid|tinyproxy|polipo|privoxy)' || dpkg -l 2>/dev/null | grep -qE 'squid|tinyproxy|polipo|privoxy'; then
    echo "[-] HTTP 代理服务器包仍然存在"
    exit 1
else
    echo "[+] HTTP 代理服务器相关包已卸载"
    exit 0
fi
